package cn.xej.health.archives.controller;

import cn.xej.health.archives.entity.Archives;
import cn.xej.health.archives.service.ArchivesService;
import cn.xej.health.common.utils.CommonResult;
import cn.xej.health.common.utils.PageUtils;
import cn.xej.health.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author xej
 */
@RefreshScope
@RestController
@RequestMapping("/archives")
public class ArchivesController {

    @Autowired
    private ArchivesService archivesService;

    @GetMapping("/list/{uuid}")
    public CommonResult list(@PathVariable("uuid")Integer uuid,@RequestParam("pageIndex")Integer pageIndex,@RequestParam("pageSize")Integer pageSize,@RequestParam("searchName")String searchName){
        return archivesService.queryList(uuid,pageIndex,pageSize,searchName);
    }


    @PostMapping("/add")
    public CommonResult add(@RequestBody Archives archives){
        archives.setCreateDate(new Date());
        archivesService.save(archives);
        return CommonResult.success(null);
    }

    @PutMapping("/update")
    public CommonResult update(@RequestBody Archives archives){
        System.out.println("更新数据");
        archivesService.updateById(archives);
        return CommonResult.success(null);
    }

    @PostMapping("/delete")
    public CommonResult delete(@RequestBody Integer[] archids){
        List<Integer> archIdList = Arrays.asList(archids);
        boolean flag = archivesService.removeByIds(archIdList);
        return flag ? CommonResult.success(null) : CommonResult.failed();
    }


    @GetMapping("/info/{archid}")
    public CommonResult info(@PathVariable("archid")Integer archid){
        return archivesService.info(archid);
    }


    @GetMapping("/divisionList")
    public CommonResult divisionList(){
        return archivesService.queryDivisionList();
    }

    @GetMapping("/teamTree/{did}")
    public CommonResult teamTree(@PathVariable("did")Integer did){
        return archivesService.queryTeamTree(did);
    }


    @GetMapping("/initDockerList/{tid}")
    public CommonResult initDockerList(@PathVariable("tid")Integer tid,@RequestParam("pageIndex")Integer pageIndex,@RequestParam("pageSize")Integer pageSize){
        return archivesService.initDockerList(tid,pageIndex,pageSize);
    }


    @PostMapping("/checkCard")
    public CommonResult checkCard(@RequestParam("card")String card){
        return archivesService.checkCard(card);
    }

}
